package com.focus.xyz.core.pages;

import com.focus.xyz.core.common.keyword.Action;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.List;

/**
 * Created by chenmeng on 2016/4/18.
 */
public class BaseTree extends BasePage {
    private Action action;

    public BaseTree(WebDriver driver,Action action) {
        super(driver,action);
    }

    private void recursive(WebElement tree, String nodeId) {
        List<WebElement> childNodes = tree.findElement(By.tagName("ul")).findElements(By.tagName("li"));
        for (WebElement childNode : childNodes) {
            String id = childNode.getAttribute("id");
            String status = childNode.getAttribute("class");
            if (cutOffNodeName(id).equals(nodeId)) {
                childNode.findElement(By.tagName("input")).click();
            } else if (status.equals("fold")) {
                childNode.findElement(By.tagName("a")).click();
                recursive(childNode, nodeId);
            }
        }
    }

    private String cutOffNodeName(String nodeId) {
        return nodeId.substring(nodeId.lastIndexOf("●") + 1, nodeId.length());
    }
}
